<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.pro.bean.*"%>


<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>所有用户信息</title>

	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrap.css">
	<script type="text/javascript" src="<%=basePath%>js/bootstrap.js"></script>
	<script type="text/javascript">
		function check()
		{
			if(document.searchform.sname.value=="")
    		{
  				alert("用户名不能为空！");
    			document.searchform.sname.focus();
   		 		return false;
    		}
		}
	</script>
  </head>
 
  <body>
   <%
		ArrayList list=(ArrayList)session.getAttribute("list");
		Iterator it=list.iterator(); 
		int intPageSize=6;  //每页显示的记录数
			int currPageBegin;  //起始记录索引	
			int AllPage;   //总页数
			int requestPage;     //用户请求页码
			String strPage;
			
			strPage=request.getParameter("pagenumber");
			 if(strPage==null)
			 {
			 requestPage=1;
			 }
			 else
			 {
			    requestPage=Integer.parseInt(strPage);
			    if(requestPage<1)
			   {
			    requestPage=1;
			    }
			 
			 }
			 AllPage=(list.size()+intPageSize-1)/intPageSize;
			 if(requestPage>AllPage)
			    requestPage=AllPage;
			currPageBegin=requestPage*intPageSize-intPageSize;	
			
		  
			if(list == null||list.size()==0)
				out.println("组为空");

		
	%>
   
    	<form name="searchform" action="<%=basePath%>servlet/SearchUserServlet" method="post" onsubmit="return check()">
    		<table border="0" align="center">
    			<tr>
    				<td>请输入需要查找的用户名：</td>
    				<td><input type="text" name="sname"></td>
    				<td><button type="submit" class="btn btn-primary" onclick="submit">提交</button></td>
    			</tr>
    		</table>
    	</form>
    		<table width="80%" align="center">
    			<tr>
   					 <td>
   						 <fieldset style="height: 100%;">
						<legend>
							<font color="#FF0000" size="2">检索结果共<%=list.size() %>件</font>
						</legend>
						<table class="table table-bordered table-hover" align="right">
    						<caption>所有用户信息</caption>
							<tr class="success">
								<td>用户ID</td>
								<td>用户名</td>
								<td>邮件地址</td>
								<td>所属部门</td>
								
								<td></td>
							</tr>
		<%for(int i=currPageBegin; i < requestPage*intPageSize&&i<list.size();i++){
			List list2=(List)session.getAttribute("list2");
			Iterator it2=list2.iterator(); 
			//System.out.println(list2.size());
		 %>
							<tr class="active">
								<td><%=((Users)list.get(i)).getUserid() %></td>
								
								<td>
									<a href="<%=basePath%>servlet/GetUserServlet?
										userId=<%=((Users)list.get(i)).getUserid() %>&
										username=<%=((Users)list.get(i)).getUsername() %>&
										useremail=<%=((Users)list.get(i)).getEmail() %>&
										userunit=<%=((Users)list.get(i)).getUnitid() %>">
										<%=((Users)list.get(i)).getUsername() %> 
									</a>
								</td>
								<td> <%=((Users)list.get(i)).getEmail() %></td>
								<td><%while(it2.hasNext()){
										Unit unit=(Unit)it2.next();	
										//System.out.println(unit.getUnitname());
										if(unit.getUnitid()==((Users)list.get(i)).getUnitid()){ 
										%>	
										<%=unit.getUnitname() %>	
										<%} 
										else if(unit.getUnitid()==0){
											%><%="null" %><%
										}	}%></td>
								
								<td><table><tr>
								<td>
									<a href="<%=basePath%>servlet/EditUserServlet?
									userId=<%=((Users)list.get(i)).getUserid() %>&
									username=<%=((Users)list.get(i)).getUsername() %>&
									useremail=<%=((Users)list.get(i)).getEmail() %>&
									userunit=<%=((Users)list.get(i)).getUnitid() %>&
									userpassword=<%=((Users)list.get(i)).getPassword() %>">
									编辑</a>
								</td>
								<td>
									<a href="<%=basePath%>servlet/DelUserServlet?userId=<%=((Users)list.get(i)).getUserid() %>">删除</a>
								</td></tr></table>
								</td>
							</tr>
			<%} %>
						</table>

						
						</fieldset>
   					 </td>
    			</tr>
   			 </table>
    		<table>
    		<tr>
    			<td width="30%" align="right">
    			<center>
                               共<%=AllPage%>页&nbsp;第<%=requestPage%>页        
          <%if(requestPage>1){ %>
            <a href="<%=basePath %>gxr/admin_super_user_view.jsp?pagenumber=<%=requestPage-1%>">上一页</a>
            <%}else{ %>
                                    上一页
         <%}%>
         <%if(requestPage<AllPage){ %>
        <a href="<%=basePath %>gxr/admin_super_user_view.jsp?pagenumber=<%=requestPage+1%>">下一页</a>
            <%}else{ %>
                                   下一页
         <%}%>
         </center>    
    			
    			</td>
    			</tr>
    			
    		</table>

  </body>
</html>
